/*
 * @Author: 陈亮
 * @LastEditors: 陈亮
 * @GitHub: https://github.com/drinkwd
 * @Description: 安全报表
 * @Date: 2019-03-22 17:02:33
 * @LastEditTime: 2019-04-08 14:49:21
 */
// 导入常用函数
import $http from '../utils/http.js'
// 定义常量
const submit = '/safeReport/submit'
const safetybasicdata = '/safeReport/safetybasicdata'
const check = '/safeReport/check'
// 定义mutation常量
const Muasafetybasicdata = '/Muasafetybasicdata/unit'
const Muasubmit = '/MuasafeReport/submit'
const Muacheck = '/safeReport/Muacheck'
export default {
  state: {
    unit: [],
    tableRiskData: [],
    tableAttackData: [],
    tableCollectionData: [],
    tablelist: [],
    collection: [],
    name: ''
  },
  actions: {
    /**
     * @description: 任务监测和受害单位
     */
    [safetybasicdata] ({ commit, dispatch }) {
      $http.post('/api/safetyForm/safetybasicdata').then(({ status, msg, data } = {}) => {
        if (status === 'success') {
          console.log(data)
          commit(Muasafetybasicdata, data)
        } else if (status === 'fail') {
          // Notification.warning(msg)
        }
      })
    },
    [submit] ({ state, commit }, form) {
      $http.post('/api/safetyformlls/submitcondition', form).then(function ({ status, data } = {}) {
        if (status === 'success') {
          commit(Muasubmit, data)
        }
      })
    },

    [check] ({ state, commit }, form) {
      $http.post('/api/safereport/checkdate', form).then(function ({ status, data } = {}) {
        if (status === 'success') {
          commit(Muacheck, data)
        }
      })
    }
  },
  mutations: {
    [Muasafetybasicdata] (state, data) {
      state.unit = data.cause
      state.collection = data.Scopetask
    },
    [Muacheck] (state, data) {
      state.tableRiskData = data.tableRisk
      state.tableAttackData = data.tableAttack
      state.tableCollectionData = data.tableCollection
    },
    [Muasubmit] (state, data) {
      state.tablelist = data.tablelist
      state.name = data.name
      if (data.reportName === 'attackevent') {
        state.tableAttackData = data.tableAttack
      } else if (data.reportName === 'riskevent') {
        state.tableRiskData = data.tableRisk
      } else {
        state.tableCollectionData = data.tableCollection
      }
    }
  }
}
